/*
 * LoginAction.java
 *
 * Copyright 2012 xwwx, Inc. All rights reserved.
 * 
 */
package com.xwwx.action;

import java.io.IOException;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.xwwx.common.CommTime;
import com.xwwx.common.Constant;
import com.xwwx.common.StringUtil;
import com.xwwx.pojo.User;
import com.xwwx.service.UserService;

/*
* @author  xwwx
* @version 1.0, 2012-11-13
* @since   JDK1.6
* 
* 接收登陆框表单
*/
public class LoginAction extends ActionSupport{

	private static final Log logger = LogFactory.getLog(LoginAction.class);
	
	/** 表单提交用户编码. */
	private String userid;
	
	/** 表单提交用户名称. */
	private String pwd;
	
	/** 用户服务接口 **/
	private UserService userService;
	
	/** 返回错误结果 **/
	private String loginerror;
	
	public String execute() throws IOException{
		
		if(StringUtil.isEmpty(userid)){
			loginerror = getText("admin.user.required");
			return "input";
		}
		if(StringUtil.isEmpty(pwd)){
			loginerror = getText("admin.password.required");
			return "input";
		}

		User user = userService.getUserByIdAndPwd(userid, pwd);
		if(user == null){
			loginerror = getText("admin.usernoexist");
			return INPUT;
		}else{
			Map<String, Object> map = ActionContext.getContext().getSession();
			map.put(Constant.USER_SESSION_KEY, user);

			return SUCCESS;
		}
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String getLoginerror() {
		return loginerror;
	}

	public void setLoginerror(String loginerror) {
		this.loginerror = loginerror;
	}

}
